package com.vfa.fishing;

import com.vfa.fishing.animal.Person;

import android.app.Dialog;
import android.content.Context;
import android.view.View;
import android.view.Window;
import android.widget.ImageButton;
import android.widget.TextView;
import android.view.View.OnClickListener;

public class ItemDialog extends Dialog implements OnClickListener
{
	
	ImageButton btnQuit;
	ImageButton btnBackward1;
	ImageButton btnForward1;
	ImageButton btnBackward2;
	ImageButton btnForward2;
	ImageButton btnBackward3;
	ImageButton btnForward3;
	int flag1;
	int flag2;
	int flag3;
	TextView tVwLengthLine;
	TextView tVwPower;
	TextView tVwScore;
	TextView tVwTime;
	Context dlgContext;
	Person boat;
	int score;
	
	public ItemDialog(Context context, Person boat) {
		super(context);
		dlgContext = context;
		// TODO Auto-generated constructor stub
		requestWindowFeature(Window.FEATURE_NO_TITLE);  
		setContentView(R.layout.item);	
		
		btnQuit = (ImageButton)findViewById(R.id.imgBtnQuit);
		btnQuit.setOnClickListener(this);
		tVwLengthLine = (TextView)findViewById(R.id.tVwLengthLine);
		tVwPower = (TextView)findViewById(R.id.tVwPower);
		tVwScore = (TextView)findViewById(R.id.tVwScore);
		tVwTime = (TextView)findViewById(R.id.tVwTime);
		tVwLengthLine.setText(String.valueOf(boat.lengthsOfline));
		tVwPower.setText(String.valueOf(boat.strength));
		tVwScore.setText(String.valueOf("Score: " + boat.amountOfMoney));
		tVwTime.setText(String.valueOf(GameActivity.iTimerInLevel));
		
		btnBackward1 = (ImageButton)findViewById(R.id.imgBtnBackward1);
		btnBackward1.setOnClickListener(this);
		btnForward1 = (ImageButton)findViewById(R.id.imgBtnForward1);
		btnForward1.setOnClickListener(this);
		btnBackward2 = (ImageButton)findViewById(R.id.imgBtnBackward2);
		btnBackward2.setOnClickListener(this);
		btnForward2 = (ImageButton)findViewById(R.id.imgBtnForward2);
		btnForward2.setOnClickListener(this);
		btnBackward3 = (ImageButton)findViewById(R.id.imgBtnBackward3);
		btnBackward3.setOnClickListener(this);
		btnForward3 = (ImageButton)findViewById(R.id.imgBtnForward3);
		btnForward3.setOnClickListener(this);
		
		flag1 = 0;
		flag2 = 0;
		flag3 = 0;
		this.boat = boat;
		score = boat.amountOfMoney;
	}
	
	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		if (v == btnQuit) {
			dismiss();
		} else if (v == btnBackward1) {
			if (flag1 > 0 && boat.amountOfMoney - score <= 40) {
				flag1--;
				boat.lengthsOfline -= 10;
				boat.amountOfMoney += 40; 
				tVwLengthLine.setText(String.valueOf(boat.lengthsOfline));
				tVwScore.setText("Score: " + boat.amountOfMoney);
			}
		} else if (v == btnForward1) {
			if (boat.amountOfMoney >= 40 && boat.lengthsOfline <= 340) {
				flag1 += 1;
				boat.lengthsOfline += 10;
				boat.amountOfMoney -= 40;
				tVwLengthLine.setText(String.valueOf(boat.lengthsOfline));
				tVwScore.setText("Score: " + boat.amountOfMoney);
			}
		} else if (v == btnBackward2) {
			if (flag2 > 0 && boat.amountOfMoney - score <= 30) {
				flag2--;
				boat.strength -= 20;
				boat.amountOfMoney += 30; 
				tVwPower.setText(String.valueOf(boat.strength));
				tVwScore.setText("Score: " + boat.amountOfMoney);
			}
		} else if (v == btnForward2) {
			if (boat.amountOfMoney >= 30) {
				flag2 += 1;
				boat.strength += 20;
				boat.amountOfMoney -= 30;
				tVwPower.setText(String.valueOf(boat.strength));
				tVwScore.setText("Score: " + boat.amountOfMoney);
			}
		} else if (v == btnBackward3) {
			if (flag3 > 0 && boat.amountOfMoney - score <= 100) {
				flag3--;
				GameActivity.iTimerInLevel -= 1;
				boat.amountOfMoney += 100; 
				tVwTime.setText(String.valueOf(GameActivity.iTimerInLevel));
				tVwScore.setText("Score: " + boat.amountOfMoney);
			}
		} else if (v == btnForward3) {
			if (boat.amountOfMoney >= 100) {
				flag3 += 1;
				GameActivity.iTimerInLevel += 1;
				boat.amountOfMoney -= 100;
				tVwTime.setText(String.valueOf(GameActivity.iTimerInLevel));
				tVwScore.setText("Score: " + boat.amountOfMoney);
			}
		}
		
	}

}
